<?php
class Application_Model_Base_Memory_Schema
{
	protected $_schema;
	
	const UN_READABLE = -100;
	
	protected $_suggestField = array(
			array('name' => 1),
			array('type' => 1),
			array('required' => 0),
			array('label' => 0),
			array("lenght" => 0)
	);
	
	public function __construct($schema)
	{
		$result = true;
		foreach ($schema as $key => $field)
		{
			foreach ($field as $index => $something)
			{
				$currentResult = false;
				foreach ($this->_suggestField as $suggest => $value)
				{
					if ($index == $suggest)
					{
						$currentResult = true;
						break;
					}
				}
				if ($currentResult == false)
				{
					$result = false;
					break;
				}
			}
		}

		foreach ($this->_suggestField as $suggest => $value)
		{
			foreach ($schema as $field)
			{
				if ($value == 1 && !isset($field[$suggest]))
				{
					$result = false;
					break;
				}
				else if ($value == 0 && !isset($field[$suggest]))
				{
					$field[$suggest] = self::UN_READABLE;
				}
			}
		}
	
		if($result == true)
		{
			$this->_schema = $schema;
		}
		else
		{
			$this->_schem = array();
		}
	}
	
	public function getSchema()
	{
		return $this->_schema;
	}
}